Skip to content

Use sorted set in SDFG construction#2398

Closed
edopao wants to merge 4 commits into
spcl:mainfrom
GridTools:dev-sorted_sets
Closed

Use sorted set in SDFG construction#2398
edopao wants to merge 4 commits into
spcl:mainfrom
GridTools:dev-sorted_sets

Conversation

@edopao

@edopao edopao commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

This PR replaces set with OrderedSet from https://github.com/rspeer/ordered-set in some places where order matters to ensure deterministic lowering.

Pulls changes from GridTools#17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make parts of DaCe’s pass pipeline and SDFG construction/lowering deterministic by replacing unordered set usage with ordered alternatives (notably ordered_set.OrderedSet) and by switching Pass.depends_on() to return an ordered collection.

Changes:

  • Add ordered-set as a dependency and introduce OrderedSet in multiple passes/graph utilities to stabilize iteration order.
  • Change Pass.depends_on() (and many implementations/tests) to return lists for deterministic dependency ordering.
  • Replace some internal set-based collections used during analysis/lowering with OrderedSet or ordered sequences.

Reviewed changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
tests/passes/pipeline_test.py Updates tests for depends_on() now returning lists.
setup.py Adds ordered-set to install requirements.
requirements.txt Pins ordered-set==4.1.0.
dace/transformation/passes/symbol_ssa.py Updates dependency declaration to a list.
dace/transformation/passes/split_tasklets.py Returns empty dependency list instead of {}.
dace/transformation/passes/scalar_fission.py Updates dependency declaration to a list.
dace/transformation/passes/reference_reduction.py Updates dependency declaration to a list.
dace/transformation/passes/pattern_matching.py Refactors dependency aggregation (currently introduces a runtime bug).
dace/transformation/passes/loop_local_memory_reduction.py Updates dependency declaration to a list.
dace/transformation/passes/lift_struct_views.py Returns empty dependency list instead of {}.
dace/transformation/passes/full_map_fusion.py Updates dependency declaration to a list.
dace/transformation/passes/dead_dataflow_elimination.py Updates dependency return value (annotation mismatch remains).
dace/transformation/passes/array_elimination.py Introduces OrderedSet for deterministic removable-data iteration.
dace/transformation/passes/analysis/scope_data_and_symbol_analysis.py Returns empty dependency list instead of {}.
dace/transformation/passes/analysis/analysis.py Broad adoption of OrderedSet (currently has set/OrderedSet operator/type issues).
dace/transformation/pass_pipeline.py Changes base depends_on() contract and pipeline dependency aggregation (currently introduces a runtime bug).
dace/transformation/helpers.py Switches post-state node collection from set to list (ordered).
dace/transformation/dataflow/map_fusion_vertical.py Uses OrderedSet for deterministic edge/connector ordering.
dace/sdfg/state.py Warns on set-based connector collections (typo in message).
dace/sdfg/scope.py Uses OrderedSet in scope subgraph collection to preserve order.
dace/sdfg/graph.py Makes all_edges deterministically ordered via OrderedSet.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +485 to +486
def depends_on(self) -> List[Type[Pass]]:
return list(dict.fromkeys([p.depends_on() for p in self.passes]))
Comment on lines +58 to +64
def depends_on(self) -> List[Union[Type['Pass'], 'Pass']]:
"""
If in the context of a ``Pipeline``, which other Passes need to run first.

:return: A set of Pass subclasses or objects that need to run prior to this Pass.
"""
return set()
return []
Comment on lines +82 to +83
def depends_on(self) -> List[Type[ppl.Pass]]:
return list(dict.fromkeys([p.depends_on() for p in self.transformations]))
Comment thread dace/transformation/passes/analysis/analysis.py
Comment on lines 276 to +279
for sdfg in top_sdfg.all_sdfgs_recursive():
arrays: Set[str] = set(sdfg.arrays.keys())
arrays: OrderedSet[str] = OrderedSet(sdfg.arrays.keys())
for block in sdfg.all_control_flow_blocks():
readset, writeset = set(), set()
readset, writeset = OrderedSet(), OrderedSet()
Comment on lines 232 to 234
for block in region.nodes():
# No symbols may be written to inside blocks.
result[block] = (block.free_symbols, set())
Comment thread dace/sdfg/state.py
Comment on lines 47 to +48
def depends_on(self) -> Set[Type[ppl.Pass]]:
return {ap.ControlFlowBlockReachability, ap.AccessSets}
return [ap.ControlFlowBlockReachability, ap.AccessSets]
that use that data descriptor.
"""
top_result: Dict[int, Dict[str, Set[nd.AccessNode]]] = dict()
top_result: Dict[int, Dict[str, OrderedSet[nd.AccessNode]]] = dict()
Comment on lines 687 to 689
block_reach: Dict[ControlFlowBlock,
Set[ControlFlowBlock]] = pipeline_results[ControlFlowBlockReachability.__name__]
OrderedSet[ControlFlowBlock]] = pipeline_results[ControlFlowBlockReachability.__name__]

@edopao edopao closed this Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants